﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Ria.ApplicationServices;
using System.Windows.Ria.Data;
using CARE.Web.Services;
using GraphInformation;
namespace CARE
{
	public partial class DiseaseSelector : UserControl
    {
        public Type sourceMethod;
        private GraphProvider gp;
        private SpreadVizualization spreadVizualization;

        public DiseaseSelector(SpreadVizualization sw)
		{
			// Required to initialize variables
			InitializeComponent();
            gp = new GraphProvider();

            spreadVizualization = sw;
		}

		private void Open_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            sourceMethod = this.GetType();

            String graphML;
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "XML Files (*.xml)|*.xml|GraphML Files (*.graphml)|*.graphml";
            Nullable<Boolean> result = dialog.ShowDialog();
            if (result.Value == true)
            {
                graphML = dialog.File.OpenText().ReadToEnd();
                var load = gp.Load(gp.GetDiseaseModelGraphQuery(graphML));
                gp.Graphs.Clear();
                load.Completed += new EventHandler(load_Completed);
            }
		}

        void load_Completed(object sender, EventArgs e)
        {
            SimulationParameters simParameters = SimulationParameters.getInstance();
            simParameters.DiseaseGraph = gp.Graphs[0];
            spreadVizualization.EnableNext();
        }

		private void Database_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
		}
	}
}
